<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>NodeCMS-添加花语</title>
    <link rel="stylesheet" href="/css/layui/css/layui.css">
    <link rel="stylesheet" href="/css/admin/reset.css">
    <link rel="stylesheet" href="/css/admin/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 公共头部 -->
    <%- include('../common/header') %>
    <!-- 公共头部 -->
    <!-- 导航条 -->
    <%- include('../common/nav') %>
    <!-- 导航条 -->
    <div class="layui-body">
        <div class="container">
            <div class="layui-form" lay-filter="item-info">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" value="<%= results.flower.title %>" name="title" lay-verify="title" id="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="position: relative;">
                    <button type="button" id="setThumb" class="layui-btn thimgbox">缩略图上传</button>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="thumbs-box">
                            <img src="<%= results.flower.thumb %>" alt="" class="layui-upload-img">
                        </div>
                    </blockquote>
                </div>
                <input type="hidden" id="thumbinput" value="<%= results.flower.thumb %>" name="thumb">
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="desc" lay-verify="content" placeholder="请输入内容" class="layui-textarea"><%= results.flower.hydesc %></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <div id="editor"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" id="submitBtn" class="layui-btn" value="立即提交">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="qiniuToken" value="<%= qiniuToken %>">
<textarea name="" id="content" style="display: none;"><%- results.flower.content %></textarea>
<input type="hidden" value="<%= results.flower.id %>" id="getFlowerId">
<script src="/js/jquery.min.js"></script>
<script src="/css/layui/layui.js"></script>
<script src="/js/wangEditor.min.js"></script>
<script src="/js/plupload.full.min.js"></script>
<script src="/js/qiniu.js"></script>
<script src="/js/xyhf.js"></script>
<script>

    var E = window.wangEditor;
    var editor = new E('#editor');
    // 或者 var editor = new E( document.getElementById('editor') )
    // 允许上传到七牛云存储
    editor.customConfig.qiniu = true;

    editor.create();
    editor.txt.html($('#content').val());
    // 初始化七牛上传
    uploadInit();
    layui.use(['element', 'form'], function(){
        var element = layui.element;
        var form = layui.form;
        var upload = layui.upload;

        $('#submitBtn').on('click', function(){
            var data = form.val('item-info');
            data.content = editor.txt.html();
            data.id = $('#getFlowerId').val();
            if(!$.trim(data.title)){
                alert('请填写标题');
                return;
            }
            $.ajax({
                url:'/cms/updateFlower',
                type:'post',
                data: data,
                success : function(d){
                    if(d.code == '200'){
                        window.location.href = '/admin/huayuList';
                    }else{
                        alert('出错了，请重新打开页面');
                    }
                }
            })
        })
    });
</script>
</body>
</html>
